import { PanelGroupKey, ScanBoardKey, SendboxKey } from "./v3pro.model";
import { V3proExternalDeviceStatus } from "../../../api/v3pro-api/v3pro.api.response.model";

/**
 * SR 上传 JSON 文件
 */
export class SRJSONFile {
  "send-boxes"?: SendboxKey[];
  "scan-boards"?: ScanBoardKey[];
  "panel-groups"?: PanelGroupKey[];
  "external-devices"?: V3proExternalDeviceStatus[];
  "layout"?: any[];

  /**
   * 检查有几项内容
   */
  getCount() {
    let ans = 0;
    Object.values(this).forEach((value) => (value ? ans++ : undefined));
    return ans;
  }

  /**
   * 存在内容的数量
   */
  getExistCount() {
    let ans = 0;
    Object.values(this).forEach((value) => (value && value.length ? ans++ : undefined));
    return ans;
  }
}

/**
 * 发送盒故障的文件 json 格式
 */
export class SRSendBoxFile extends SRJSONFile {
  constructor(keys: SendboxKey[], layout?: any[]) {
    super();
    this["send-boxes"] = keys;
    this["layout"] = layout;
  }
  static build(keys: SendboxKey[], layout?: any[]) {
    return new SRSendBoxFile(keys, layout);
  }

  static buildToSRJSONFile(keys: SendboxKey[], json: SRJSONFile) {
    json["send-boxes"] = keys;
    return json;
  }
}

/**
 * 扫描板故障的文件 json 格式
 */
export class SRScanBoardFile extends SRJSONFile {
  constructor(keys: ScanBoardKey[], layout?: any[]) {
    super();
    this["scan-boards"] = keys;
    this["layout"] = layout;
  }
  static build(keys: ScanBoardKey[], layout?: any[]) {
    return new SRScanBoardFile(keys, layout);
  }

  static buildToSRJSONFile(keys: ScanBoardKey[], json: SRJSONFile) {
    json["scan-boards"] = keys;
    return json;
  }
}

/**
 * 扫描板故障的文件 json 格式
 */
export class SRPanelGroupFile extends SRJSONFile {
  constructor(keys: PanelGroupKey[], layout?: any[]) {
    super();
    this["panel-groups"] = keys;
    this["layout"] = layout;
  }
  static build(keys: PanelGroupKey[], layout?: any[]) {
    return new SRScanBoardFile(keys, layout);
  }

  static buildToSRJSONFile(keys: PanelGroupKey[], json: SRJSONFile) {
    json["panel-groups"] = keys;
    return json;
  }
}

/**
 * 外部设备故障的文件 json 格式
 */
export class SRExternalDeviceFile extends SRJSONFile {
  constructor(devicesStatus: V3proExternalDeviceStatus[], layout?: any[]) {
    super();
    this["external-devices"] = devicesStatus;
    this["layout"] = layout;
  }
  static build(devicesStatus: V3proExternalDeviceStatus[], layout?: any[]) {
    return new SRExternalDeviceFile(devicesStatus, layout);
  }

  static buildToSRJSONFile(keys: V3proExternalDeviceStatus[], json: SRJSONFile) {
    json["external-devices"] = keys;
    return json;
  }
}
